package com.bawei.user

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.bean.UserEntity
import com.bawei.base.mvvm.BaseActivity
import com.bawei.base.mvvm.BaseViewActivity
import com.bawei.user.databinding.ActivityUserBinding
import com.blankj.utilcode.util.ToastUtils
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.*
@AndroidEntryPoint
@Route(path = "/user/UserActivity")
class UserActivity : BaseActivity<ActivityUserBinding, UserViewModel>() {
    lateinit var userTypeAdapter: UserTypeAdapter
    lateinit var userAdapter: UserAdapter
    val userList= mutableListOf<UserEntity>()
    var index=0
    override fun initView() {
        viewModel.user(9)
        userAdapter= UserAdapter()
        val listTitle= mutableListOf<String>()
        listTitle.add("全部")
        listTitle.add("正常")
        listTitle.add("迟到")
        listTitle.add("早退")
        listTitle.add("缺勤")
        binding.userRec.adapter=userAdapter
        binding.userRec.layoutManager=LinearLayoutManager(this)
        userTypeAdapter= UserTypeAdapter()
        userTypeAdapter.data.clear()
        userTypeAdapter.data.addAll(listTitle)
        binding.userTyperec.adapter=userTypeAdapter
        binding.userTyperec.layoutManager=LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false)
        userTypeAdapter.setOnItemClickListener { _, _, position ->

            userTypeAdapter.setType(userTypeAdapter.data[position],index,position)
            index=position
            userAdapter.data.clear()
            when(position){
                0->{
                    userAdapter.data.addAll(userList)
                }
                1->{
                    userList.forEach {
                        if (it.status=="1"){
                            userAdapter.data.add(it)
                        }
                    }
                }
                2->{
                    userList.forEach {
                        if (it.status=="2"){
                            userAdapter.data.add(it)
                        }
                    }
                }
                3->{
                    userList.forEach {
                        if (it.status=="3"){
                            userAdapter.data.add(it)
                        }
                    }
                }
                4->{
                    userList.forEach {
                        if (it.status=="4"){
                            userAdapter.data.add(it)
                        }
                    }
                }
            }
            userAdapter.notifyDataSetChanged()
        }
        binding.userPunch.setOnClickListener {
            ARouter.getInstance().build("/user/UserCheckActivity").navigation()
        }
    }

    override fun initData() {
        viewModel.userSuccess.observe(this){
            userList.clear()
            userList.addAll(it)
            userAdapter.data.clear()
            userAdapter.data.addAll(it)
            userAdapter.notifyDataSetChanged()
        }
    }


}